package org.nyt.medicalstore.service.impl;

import org.nyt.medicalstore.model.Drug;
import org.nyt.medicalstore.repository.DrugRepository;
import org.nyt.medicalstore.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class DrugServiceImpl implements DrugService {
    @Autowired
    private DrugRepository drugRepository;

    @Override
    public Drug saveDrug(Drug drug) {
        return drugRepository.save(drug);
    }

    @Override
    public Drug getDrugById(Long id) {
        Optional<Drug> drug = drugRepository.findById(id);
        return drug.orElse(null);
    }

    @Override
    public List<Drug> getAllDrugs() {
        return drugRepository.findAll();
    }

    @Override
    public void deleteDrug(Long id) {
        drugRepository.deleteById(id);
    }
} 